package se.mushroomwars.gameplay;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;

import javax.swing.JComponent;

import se.mushroomwars.network.ClientInterface;

@SuppressWarnings("serial")
public class View extends JComponent implements DrawingListener {
	private ClientInterface gamePlay;
	
	public View(ClientInterface gamePlay){
		
		this.gamePlay = gamePlay;
		gamePlay.addDrawingListener(this);
		//keyController.addDrawingListener(this);
		
		Toolkit tk = Toolkit.getDefaultToolkit();  
		int xSize = ((int) tk.getScreenSize().getWidth());  
		int ySize = ((int) tk.getScreenSize().getHeight());  
		setSize(xSize,ySize);
		
		// Request a specific size
		//setMinimumSize(new Dimension(320, 200));
		setPreferredSize(new Dimension(xSize, ySize));
	}

	public void paintComponent(final Graphics g) {
		 Graphics2D g2 = (Graphics2D) g;
	        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
	          RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	        g2.setRenderingHint(RenderingHints.KEY_RENDERING,
	          RenderingHints.VALUE_RENDER_QUALITY);
	        super.paintComponent(g2);	        
	 }

	@Override
	public void notifyDrawingChanged() {
		// Whenever something changed in the drawing,
		// we simply repaint the entire component.  This will call various
		// methods in the Swing library that ensures that eventually,
		// in another thread, our own paintComponent() method will be called.
		repaint();		
	}

}
